For each external type named <E>
, the following
two functions are generated, which convert a value of type
<E>
into its object representation and vice versa:
sos_Object make_<E>_object (E); E make_<E> (sos_Object);
For the conversion from sos_Object
to <E>
a dynamic type check is performed.
The object that results from make_<E>_object
is of the class sos_Scalar_object
; this class
is declared in the kernel schema and described in
Appendix .
The generated functions will make use of some conversion operations that
must be provided by the schema implementor.
For this purpose, for each external type named <E>
, the file
<schema-name>_ext.h
must define a C++ type with the same name together
with following functions:
void bcopy_from_<E> (void *e, void *c) void bcopy_to_<E> (void *e, void *c)
These functions convert a value of type <E>
(pointed to by the
parameter e
) to its standard representation
(see also Section )
of n
bytes
(pointed to by the parameter c
) and vice versa.n
is the size of the external type as denoted
in the external type declaration in the schema. Note that a standard
representation of an external type is needed to achieve a language and
machine independent storage of objects.
Additionally two functions that convert an external type into an sos_String must be provided, to enable the development of generic I/O routines.
sos_String make_string_from_<E>_object (sos_Object); sos_Object make_<E>_object_from_string (sos_String);
By convention, the string returned by the first conversion operation has to be created in the TEMP_CONTAINER. It is up to the caller of this function to destroy this string object. Also by convention, the conversion operations should return NO_OBJECT on failure.
Example:
For the type sos_Char
, whose standard representation takes one byte,
these operations might look as follows:
inline void bcopy_from_sos_Char (void *sos_ch, void *c) { *(char*)c = (char*)(sos_Char*)sos_ch; } inline void bcopy_to_sos_Char (void *sos_ch, void *c) { *(sos_Char*)sos_ch = (char*)c; }
sos_String make_string_from_sos_Char_object (sos_Object c) { sos_Char s[2]; s[0] = make_sos_Char (c); s[1] = '\0'; sos_String result = sos_String::create (TEMP_CONTAINER); result.assign_Cstring (s); return result; } sos_Object make_sos_Char_object_from_string (sos_String s) { sos_Cstring s1 = s.make_Cstring(); sos_Object result; if (strlen (s1) == 1) result = make_sos_Char_object (s1[0]); else result = NO_OBJECT; delete s1; return result; }